package com.wali.modules.system.service;

import com.wali.common.ccp.secret.CcpSecretManager;
import com.wali.modules.system.bo.SysUserBO;
import com.wali.modules.system.dao.ISysUserDao;
import com.wali.modules.system.vo.SysUserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author walixu
 * @ClassName com.wali.modules.system.service
 * @Description ${todo}
 * @email wali.xu@kpmg.com
 * @date 11/11/2018 8:43 下午
 */
@Service
public class SysUserService {

    @Autowired
    private ISysUserDao iUserDao;

    /**
     * @param sysUser
     * @return
     * @throws
     * @Title regSysUser
     * @Description 注册用户
     */
    public int regSysUser(SysUserBO sysUser) {
        SysUserVO sysUserVO = SysUserBO.convert(sysUser);
        sysUserVO.setPassword(CcpSecretManager.getInstance().encryptMD5(sysUserVO.getPassword()));
        return iUserDao.saveSysUser(sysUserVO);
    }

    /**
     * @param username 用户名
     * @return boolean
     * @throws
     * @Title checkSysUserExist
     * @Description 校验用户名是否已经存在
     */
    public boolean checkSysUserExist(String username) {
        SysUserVO sysUser = new SysUserVO();
        sysUser.setUsername(username);
        sysUser = iUserDao.getSysUser(sysUser);

        if (sysUser == null) {
            return false;
        }
        return true;
    }

    /**
     * @param sysUser
     * @return SysUserVO
     * @throws
     * @Title getSysUser
     * @Description 查询单条用户基本信息
     */
    public SysUserVO getSysUser(SysUserBO sysUser) {
        SysUserVO sysUserVO = SysUserBO.convert(sysUser);
        sysUserVO.setPassword(CcpSecretManager.getInstance().encryptMD5(sysUserVO.getPassword()));
        return iUserDao.getSysUser(sysUserVO);
    }

    /**
     * @param
     * @return
     * @throws
     * @Title updateUserPassword
     * @Description 修改用户密码
     */
    public int updateUserPassword(SysUserBO sysUser) {
        SysUserVO sysUserVO = SysUserBO.convert(sysUser);
        return iUserDao.updateSysUser(sysUserVO);
    }

}
